﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _56写入文件
{
    class Program
    {
        static void Main(string[] args)
        {
            //覆盖写入
            #region WriteAllBytes
            //string str = "今天真是好冷啊";
            ////将字符串转换成字节数组
            //byte[] buffer = System.Text.Encoding.Default.GetBytes(str);
            //File.WriteAllBytes(@"C:\Users\Administrator\Desktop\2.txt", buffer);
            //Console.WriteLine("写入成功");
            //Console.ReadKey();
            #endregion

            #region WriteAllLines
            //string[] name = { "张三", "李四", "赵六", "王五" };
            //File.WriteAllLines(@"C:\Users\Administrator\Desktop\1.txt",name);
            //Console.WriteLine("写入成功");
            //Console.ReadKey();
            #endregion

            #region WriteAllText
            //File.WriteAllText(@"C:\Users\Administrator\Desktop\1.txt", "明天休息，在家好好敲代码");
            //Console.WriteLine("写入成功");
            //Console.ReadKey();
            #endregion


            //非覆盖写入
            #region AppendAllText
            //File.AppendAllText(@"C:\Users\Administrator\Desktop\1.txt","看我有没有把字覆盖掉");
            //Console.WriteLine("写入成功");
            //Console.ReadKey();
            #endregion
        }
    }
}
